//
//  RecommendTableViewCell.m
//  homeland
//
//  Created by rain on 14-5-12.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "RecommendTableViewCell.h"

@implementation RecommendTableViewCell

- (void)awakeFromNib
{
    // Initialization code

}

- (void)setInitSubView;
{
    self.mobileLabel.hidden = YES;
    self.registerLabel.hidden = YES;
    self.phoneBtn.hidden = YES;
    self.moreLabel.hidden = YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)updateDetial:(RecommendListItem *)item;
{
    self.mobileLabel.hidden = NO;
    self.registerLabel.hidden = NO;
    self.phoneBtn.hidden = NO;
    self.moreLabel.hidden = YES;
    
    self.mobileLabel.text = item.mobile;
    self.registerLabel.text = item.isRegister ? @"已注册" : @"未注册";
    self.registerLabel.textColor = item.isRegister ? HEXCOLOR(0xfea444) : HEXCOLOR(0x8c8c8c);
}

- (IBAction)callPhone:(id)sender
{
//    NSRegularExpressionSearch
    NSString *txt = self.mobileLabel.text;
//    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{4}[-]{0,1}[0-9]{4}?" options:0 error:nil];
//    NSTextCheckingResult *result = [regex firstMatchInString:txt options:0 range:NSMakeRange(0, [txt length])];
//    NSString *cleanedString = [[[txt substringWithRange:[result range]] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
//    NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    
////    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8008808888"]];
//    NSLog(@"escapedPhoneNumber = %@",escapedPhoneNumber);
    NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@", txt]];
    [[UIApplication sharedApplication] openURL:telURL];
}
@end
